package mapreduce;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class PhoneFlow implements WritableComparable<PhoneFlow> {

    private String phone;

    private long upFlow;

    private long downFlow;

    private long flowSum;

    public PhoneFlow(){}

    public void set(String phone,long upFlow,long downFlow,long flowSum){
        this.phone = phone;
        this.upFlow = upFlow;
        this.downFlow = downFlow;
        this.flowSum = flowSum;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public long getUpFlow() {
        return upFlow;
    }

    public void setUpFlow(long upFlow) {
        this.upFlow = upFlow;
    }

    public long getDownFlow() {
        return downFlow;
    }

    public void setDownFlow(long downFlow) {
        this.downFlow = downFlow;
    }

    public long getFlowSum() {
        return flowSum;
    }

    public void setFlowSum(long flowSum) {
        this.flowSum = flowSum;
    }

    public String toString(){
        return this.phone+"\t"+this.upFlow+"\t"+this.downFlow+"\t"+this.flowSum+"\r\n";
    }

    public boolean equals(PhoneFlow o){
        return this.phone.equals(o.phone);
    }

    @Override
    public int compareTo(PhoneFlow o) {
        if(this.getFlowSum() >= o.getFlowSum()){
            return -1;
        }else{
            return 1;
        }
        //return 0;
    }


    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(this.phone);
        dataOutput.writeLong(this.upFlow);
        dataOutput.writeLong(this.downFlow);
        dataOutput.writeLong(this.flowSum);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.phone= dataInput.readUTF();
       this.upFlow = dataInput.readLong();
       this.downFlow = dataInput.readLong();
       this.flowSum = dataInput.readLong();
    }
}
